package com.xiebishe.mylibrary.common.glide;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.widget.ImageView;

import com.xiebishe.mylibrary.common.glide.glide.GlideImageLoaderStrategy;


public class ImageLoader {
    private static IImageLoaderStrategy mStrategy = new GlideImageLoaderStrategy();

    public ImageLoader() {
    }
    public static ImageLoadRequestBuilder with(Context context) {
        return new ImageLoadRequestBuilder(context);
    }
    public void setLoadImgStrategy(IImageLoaderStrategy strategy) {
        mStrategy = strategy;
    }


    static void loadImage(Context context, String url, boolean isSvg, boolean isCircle, boolean isCenterCrop, boolean autoFitUrlToCutting, boolean autoFitUrlToSize, Drawable placeHolder, Drawable errorHolder, ImageView imageView, int viewWidth, int viewHeight) {
        if (mStrategy != null) {
            mStrategy.loadImage(context, url, isSvg, isCircle, isCenterCrop, autoFitUrlToCutting, autoFitUrlToSize, placeHolder, errorHolder, imageView, viewWidth, viewHeight);
        }

    }

    public static boolean checkImageExist(String url) {
        return TextUtils.isEmpty(url) ? false : mStrategy.checkImageExist(url);
    }

    public static void clearImageDiskCache(Context context) {
        mStrategy.clearImageDiskCache(context);
    }

    public static void clearImageMemoryCache(Context context) {
        mStrategy.clearImageMemoryCache(context);
    }

    public static void trimMemory(Context context, int level) {
        mStrategy.trimMemory(context, level);
    }

    public static void clearImageAllCache(Context context) {
        clearImageDiskCache(context.getApplicationContext());
        clearImageMemoryCache(context.getApplicationContext());
    }

    public static long getCacheSize(Context context) {
        return mStrategy.getCacheSize(context);
    }


    public static String parseImageUrl(String url, int width, int height, boolean needCutting) {
        return UrlRequestOption.of(url).setSourceWidth(width).setSourceHeight(height).setNeedCutting(needCutting).build();
    }


    public static final void resumeRequest(Context context) {
        mStrategy.resumeRequest(context);
    }
}

